<template>
  <div class="article-container">
    <!--面包导航区域  -->
    <breadcrumb></breadcrumb>

    <!-- 塞选卡片1 -->

    <!--  -->
    <el-card style="margin-top: 15px">
      <!-- 标题 -->
      <div slot="header" class="clearfix">
        <el-row :gutter="20" type="flex" justify="flex-end">
          <el-col :span="2">
            <el-button type="primary" @click="contactAdd">添加</el-button>
          </el-col>
        </el-row>
      </div>

      <!-- 招聘表格 -->
      <el-table
        :data="contacts"
        stripe
        style="width: 100%"
        :default-sort = "{prop:'pubdate',order: 'descending'}"
      >

        <el-table-column prop="title" label="标题"> </el-table-column>
        <el-table-column prop="email" label="邮箱"> </el-table-column>
        <el-table-column prop="pudate" label="发布时间" > </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-tooltip effect="dark" content="修改信息" placement="top">
              <el-button
                type="primary"
                icon="el-icon-edit"
                size="mini"
                @click="contactEdit(scope.row.id)"
              ></el-button>
            </el-tooltip>
            <el-tooltip effect="dark" content="删除" placement="top" >
              <el-button
                type="danger"
                icon="el-icon-delete"
                size="mini"
                @click="deleteDialog(scope.row)"
              ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页组件 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="queryInfo.per_page"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total_count"
      >
      </el-pagination>
    </el-card>

    <!-- 删除招聘对话框 -->
    <el-dialog title="删除用户" :visible.sync="deleteDialogVisble" width="50%">
      <span>您确定删除该招聘吗？</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="deleteDialogVisble = false">取消</el-button>
        <el-button type="primary" @click="deleteBanner">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import Breadcrumb from "@/components/Breadcrumb.vue";
import { getContact,postDeleteContact} from "@/api/contact";
export default {
  components: {
    Breadcrumb,
  },
  data() {
    return {
      //招聘表格数据
      contacts: [
        // pubdate
      ],
      //招聘请求参数
      queryInfo: {
        pagenum: 1,
        per_page: 5,
      },
      //招聘总数
      total_count: null,
      //招聘删除参数
      deleteParams:{
        id:null
      },
      //添加招聘
      addDialogVisble:false,
      //删除招聘对话框显示隐藏
      deleteDialogVisble:false,
    };
  },
  computed: {},
  methods: {
    //获取招聘数据
    async loadContacts() {
      const { data: res } = await getContact(this.queryInfo);
      console.log(res);
      this.contacts = res.data;
      console.log(this.contacts)
      this.total_count = res.total_count;
    },
    //监听pape改变的事件
    handleCurrentChange(newPage) {
      this.queryInfo.pagenum = newPage;
      this.loadArticles();
    },
    //监听per_page改变的事件
    handleSizeChange(newSize) {
      this.queryInfo.per_page = newSize;
      this.loadArticles();
    },
    //去招聘添加区域
    contactAdd(){
      this.$router.push('/contact/add')
    },
    //去招聘修改编辑区域
    contactEdit(id){
      this.$router.push('/contact/edit/'+ id)
    },
    //删除招聘对话框显示
    deleteDialog(row){
      console.log(row)
      this.deleteDialogVisble = true
      this.deleteParams = {
        id:row.id
      }
    },
    //删除招聘
    async deleteBanner(){
      const {data:res} = await postDeleteContact(this.deleteParams)
      if(res.meta.status !== 200) return this.$message.error('删除招聘信息失败')
      this.$message.success('删除招聘信息成功')
      this.deleteDialogVisble = false
      this.loadContacts()
    }
  },
  created() {
    //调用招聘数据
    this.loadContacts();
  },
  mounted() {},
};
</script>

<style lang='less' scoped>
.article-cover {
  width: 50%;
  background-size: cover;
}
</style>